package com.springboot.service;

import com.hqj.ReturnUtil;
import com.springboot.annotation.OperationLogDetail;
import com.springboot.dao.TestRepository;
import com.springboot.domain.OperationTypeEnum;
import com.springboot.domain.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class TestServiceI implements BaseService<Test> {

    @Autowired
    private TestRepository tr;


    @Override
    public List<Test> find(Test test) {
        return tr.findAll();
    }

    public List<Test> findByName(String name){
        List<Test> list = tr.findByName(name);
        return list;
    }

    public List<Test> queryByNameHQL(String name,String sex){
        List<Test> list = tr.queryByNameHQL(name,sex);
        return list;
    }

    @Override
    public Test get(Test test) {
        return null;
    }

    @Override
    @OperationLogDetail(userId = "123",unit = "ssm_test",type = OperationTypeEnum.INSERT)
    public Map<String, Object> add(Test test) {
        test = tr.save(test);
        return ReturnUtil.returnMap(test!=null,"新增");
    }

    @OperationLogDetail(userId = "{{userId}}",unit = "ssm_test",type = OperationTypeEnum.INSERT)
    public Map<String, Object> add(Test test,String userId) {
        test = tr.save(test);
        return ReturnUtil.returnMap(test!=null,"新增");
    }

    public Map<String,Object> updateNameByIdHQL(String name,int id){
        boolean b = false;
        try {
            tr.updateNameByIdHQL(name, id);
            b = true;
        }catch (Exception e){
            e.printStackTrace();
            b = false;
        }
        return ReturnUtil.returnMap(b,"编辑");
    }

    @Override
    public Map<String, Object> edit(Test test) {
        return null;
    }

    @Override
    public Map<String, Object> remove(Test test) {
        return null;
    }
}
